#include "../../config.h"

#include <glibmm/i18n.h>

#include "../application.h"
#include "../conf.h"
#include "p_record.h"
#include "p_macros.h"

namespace gpyp {
namespace pref {

//========================
// Record
Record::Record(Application &app, Gtk::Window &/*parent*/) :
  Gtk::VBox       (false, 2),
  retry_ch_exists_(_("Force retry when channel is exists")),
  rm_zero_file_   (_("Remove recorded file when file size is 0")),
  term_on_exit_   (_("Terminate recording process on exit")),
  kill_on_exit_   (_("Send KILL")),
  log_save_       (_("Save log"))
{
  for(const char **p = ConfMain::Record::PRESETS; *p; ++p) command_.append_text(*p);
  SETUP_SPINBUTTON(retry_timeout_,  3, 300);
  SETUP_SPINBUTTON(retry_count_,   -1,  10);

  Gtk::Table *t1 = Gtk::manage(new Gtk::Table());
  TABLE_LABEL(*t1, 0, _("Command"));
  TABLE_LABEL(*t1, 1, _("File name"));
  TABLE_LABEL(*t1, 2, _("Retry timeout(sec)"));
  TABLE_LABEL(*t1, 3, _("Retry count"));
  t1->attach(command_,       1, 2, 0, 1);
  t1->attach(filename_,      1, 2, 1, 2);
  t1->attach(retry_timeout_, 1, 2, 2, 3);
  t1->attach(retry_count_,   1, 2, 3, 4);
  t1->set_col_spacings(2);
  t1->set_row_spacings(2);
  pack_start(*t1,              false, false);
  pack_start(retry_ch_exists_, false, false);
  pack_start(rm_zero_file_,    false, false);
  pack_start(term_on_exit_,    false, false);
  Gtk::Alignment *a1 = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_TOP));
  a1->set_padding(0, 0, 16, 0);
  a1->add(kill_on_exit_);
  pack_start(*a1, false, false);

  Gtk::Table *t2 = Gtk::manage(new Gtk::Table());
  TABLE_LABEL(*t2, 1, _("File name"));
  t2->attach(log_save_,     0, 2, 0, 1);
  t2->attach(log_filename_, 1, 2, 1, 2);
  t2->set_col_spacings(2);
  t2->set_row_spacings(2);
  t2->set_border_width(2);
  Gtk::Frame *f1 = Gtk::manage(new Gtk::Frame(_("Log")));
  f1->add(*t2);
  pack_start(*f1, false, false);

  ConfMain::RefRecord r = app.conf().record();
  r->command()        ->attach(command_.get_entry()->property_text());
  r->filename()       ->attach(filename_            .property_text());
  r->retry_timeout()  ->attach(retry_timeout_       .property_value());
  r->retry_count()    ->attach(retry_count_         .property_value());
  r->retry_ch_exists()->attach(retry_ch_exists_     .property_active());
  r->rm_zero_file()   ->attach(rm_zero_file_        .property_active());
  r->term_on_exit()   ->attach(term_on_exit_        .property_active());
  r->term_on_exit()   ->attach(kill_on_exit_        .property_sensitive());
  r->kill_on_exit()   ->attach(kill_on_exit_        .property_active());
  r->save_log()       ->attach(log_save_            .property_active());
  r->log_filename()   ->attach(log_filename_        .property_text());
}

}/*pref*/
}/*gpyp*/
